//index.js
//获取应用实例
var app = getApp();
Page({
    data: {
        config: [{ title: '发需求', message: '一键提交', mtype: '1' }, { title: '找应用', message: '即装即用、省时省心', mtype: '2' }, { title: '小程序', message: '定制你的首款小程序', mtype: '3' }],
        itemData: [],
        nav: { home: { icon: '../../resource/icon/home.png', text: '首页' }, tel: { icon: '../../resource/icon/mobile.png', text: '电话' }, qa: { icon: '../../resource/icon/liuyan.png', text: '咨询' }, nav: { icon: '../../resource/icon/map.png', text: '导航' } },
        mobile: '0573-8888888',
        location: ''
    },
    //事件处理函数

    checkTap: function() {
        wx.navigateTo({
            url: '../check/check'
        })
    },


    bindSubmit: function(e) {
        let index = e.currentTarget.dataset.index;
        wx.navigateTo({
            url: '../post/post?index=' + index,
        })
    },
    item_onclick: function(e) {
        let id = e.currentTarget.dataset.id;


        wx.navigateTo({
            url: '../detail/detail?id=' + id
        })
    },
    onShareAppMessage: function() {

    },
    homeTap: function() {
        wx.PullDownRefresh();

    },
    mobileTap: function() {
        wx.makePhoneCall({
            phoneNumber: this.data.mobile,
            success: function() {

            },
            fail: function() {

            }
        })
    },
    msgTap: function() {

    },
    mapTap: function() {
        wx.openLocation({
            latitude: this.data.location.lat,
            longitude: this.data.location.lng,
            name: this.data.title,
            address: '平湖市客运中心3楼绿骆驼科技有限公司',
            scale: 28,
        })
    },
    onLoad: function() {

        var that = this
        app.util.request({
            'url': 'entry/wxapp/baseinfo',
            data: {
                m: 'llt_xappsc'
            },
            'cachetime': '30',
            success: function(res) {

                var temData = res.data.data
                let navdata = res.data.data.navs
                let name = res.data.data.name;
                wx.setNavigationBarTitle({
                    title: name //页面标题为路由参数
                })

                that.setData({
                    title: temData.title,
                    logo: temData.logo,
                    'config[0].logo': temData.req_entry.icon,
                    'config[1].logo': temData.app_entry.icon,
                    'config[2].logo': temData.wxapp_entry.icon,
                    // nav: Object.assign(that.data.nav, navdata),
                    'nav.home': { icon: navdata.home.icon || that.data.nav.home.icon, text: navdata.home.text || that.data.nav.home.text },
                    'nav.nav': { icon: navdata.nav.icon || that.data.nav.nav.icon, text: navdata.nav.text || that.data.nav.nav.text },
                    'nav.qa': { icon: navdata.qa.icon || that.data.nav.qa.icon, text: navdata.qa.text || that.data.nav.qa.text },
                    'nav.tel': { icon: navdata.tel.icon || that.data.nav.tel.icon, text: navdata.tel.text || that.data.nav.tel.text },
                    mobile: temData.tel,
                    location: temData.location

                })

            }
        });

        app.util.request({
            'url': 'entry/wxapp/apps',
            data: {
                m: 'llt_xappsc'
            },
            'cachetime': '30',
            success: function(res) {
                var itemData = res.data.data
                that.setData({
                    itemData: itemData
                })
                console.log(that.data.itemData)
            }
        });
    },

    onPullDownRefresh: function() {
        this.dorequest();

    },
    dorequest: function() {
        var that = this
        app.util.request({
            'url': 'entry/wxapp/apps',
            data: {
                m: 'llt_xappsc'
            },
            'cachetime': '30',
            success: function(res) {
                var itemData = res.data.data
                that.setData({
                    itemData: itemData
                })
                wx.stopPullDownRefresh()
            }
        });
    },
    cb(func) {

    }
})